#define _CRT_SECURE_NO_WARNINGS 1

#include"Sort.h"


void InsertSortTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	InsertSort(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void BubbleSortTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	BubbleSort(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void HeapSortTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	HeapSort(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void ShellSortTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	ShellSort(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void SelectSortTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	SelectSort(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void QuickSort1Test()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	QuickSort1(a, 0, sizeof(a) / sizeof(int) - 1);
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void QuickSort2Test()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	QuickSort2(a, 0, sizeof(a) / sizeof(int) - 1);
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void QuickSort3Test()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	QuickSort3(a, 0, sizeof(a) / sizeof(int) - 1);
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void QuickSort4Test()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	QuickSort4(a, 0, sizeof(a) / sizeof(int) - 1);
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void QuickSortNonRTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	QuickSortNonR(a, 0, sizeof(a) / sizeof(int) - 1);
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void MergeSortTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	MergeSort(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void MergeSortNonRTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8};
	MergeSortNonR(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}


void CountSortTest()
{
	int a[] = { 5, 3, 9, 6, 2, 4, 7, 1, 8 };
	CountSort(a, sizeof(a) / sizeof(int));
	PrintfArray(a, sizeof(a) / sizeof(int));
}

void TestOP()
{
	srand(time(0));
	const int N = 100;
	int* a1 = (int*)malloc(sizeof(int) * N);
	int* a2 = (int*)malloc(sizeof(int) * N);
	int* a3 = (int*)malloc(sizeof(int) * N);
	int* a4 = (int*)malloc(sizeof(int) * N);
	int* a5 = (int*)malloc(sizeof(int) * N);
	int* a6 = (int*)malloc(sizeof(int) * N);
	int* a7 = (int*)malloc(sizeof(int) * N);
	int* a8 = (int*)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++)
	{
		a1[i] = i;
		/*a1[i] = rand() % N;*/
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
		a8[i] = a1[i];
	}
	int begin1 = clock();
	InsertSort(a1, N);
	int end1 = clock();

	int begin2 = clock();
	BubbleSort(a2, N);
	int end2 = clock();

	int begin3 = clock();
	HeapSort(a3, N);
	int end3 = clock();

	int begin4 = clock();
	ShellSort(a4, N);
	int end4 = clock();

	int begin5 = clock();
	SelectSort(a5, N);
	int end5 = clock();

	int begin6 = clock();
	QuickSort1(a6, 0, N - 1);
	int end6 = clock();

	int begin7 = clock();
	QuickSort2(a7, 0, N - 1);
	int end7 = clock();

	int begin8 = clock();
	QuickSort3(a7, 0, N - 1);
	int end8 = clock();

	printf("InsertSort: %d\n", end1 - begin1);
	printf("BubbleSort: %d\n", end2 - begin2);
	printf("HeapSort:   %d\n", end3 - begin3);
	printf("ShellSort:  %d\n", end4 - begin4);
	printf("SelectSort: %d\n", end5 - begin5);
	printf("QuickSort1: %d\n", end6 - begin6);
	printf("QuickSort2: %d\n", end7 - begin7);
	printf("QuickSort3: %d\n", end8 - begin8);
	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
	free(a7);
	free(a8);
}




int main()
{
	TestOP();
	return 0;
}